package com.hcy.performancepro.controller.performanceTool;

import com.fuled.test.tool_config.DisableUtil;
import com.hcy.performancepro.bo.performanceTool.RecordControllerBo;
import com.hcy.performancepro.bo.performanceTool.RecordEntityBo;
import com.hcy.performancepro.po.performanceTool.RecordEntity;
import com.hcy.performancepro.service.performanceTool.PerformanceToolEntityService;
import com.hcy.performancepro.util.ResultData;
import com.hcy.performancepro.vo.performanceTool.RecordEntityVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/performanceEntity")
@DisableUtil
@RequiredArgsConstructor
public class PerformanceToolEntityController {
    private final PerformanceToolEntityService performanceToolEntityService;

    @PostMapping("/page")
    public ResultData<Object> page(@RequestParam Integer currentPage, @RequestParam Integer pageSize,@RequestBody RecordEntityBo recordEntityBo){
        List<RecordEntity> list = performanceToolEntityService.sarchlist(currentPage, pageSize,recordEntityBo);
        List<RecordEntityVo> listVo = new ArrayList<>();
        if(list != null && !list.isEmpty()){
            for (RecordEntity obj : list) {
                RecordEntityVo vo = new RecordEntityVo();
                BeanUtils.copyProperties(obj, vo);
                listVo.add(vo);
            }
        }
        return ResultData.ok(listVo);
    }

    @GetMapping("/count")
    public ResultData<Object> count(RecordEntityBo recordEntityBo){
        return ResultData.ok(performanceToolEntityService.countNumber(recordEntityBo));
    }
}